using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace AnimationPage.Converters;

public sealed class TimeToReadTimeConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        // Get the time passed in
        if (value is not DateTimeOffset time)
            return null;

        // If it is not read...
        if (time == DateTimeOffset.MinValue)
            // Show nothing
            return string.Empty;

        // If it is today...
        if (time.Date == DateTimeOffset.UtcNow.Date)
            // Return just time
            return $"Read {time.ToLocalTime().ToString("HH:mm")}";

        // Otherwise, return a full date
        return $"Read {time.ToLocalTime().ToString("HH:mm, dd MMM yyyy")}";
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}